package com.test.demo.consumer;

import com.test.demo.provider.service.DemoService;
import org.apache.dubbo.config.annotation.Reference;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;

@SpringBootTest
class AsyncCosumer {

    @Reference(version = "async")
    private DemoService demoService;
    @Test
    void contextLoads() {
        CompletableFuture<String> completableFuture = demoService.asyncSayHello("world");
        completableFuture.whenComplete((v,t)->{
            if (t!=null){
                t.printStackTrace();
            }else {
                System.out.println("Responce:"+v);
            }
        });
        //等待future执行完成
        CompletableFuture.allOf(completableFuture).join();
        // 早于结果输出
        System.out.println("Executed before response return.");
    }

}
